  public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }

class Solution {
 private int index ;
 public TreeNode buildTree(int[] inorder, int[] postorder) {
  this.index = postorder.length -1 ;
  return buildTreeChild(inorder , 0 , inorder.length-1 , postorder);
 }

 private TreeNode buildTreeChild(int[] inorder , int begin , int end ,
                                 int[] postorder ){
  if(this.index >= postorder.length || begin> end){
   return null ;
  }
  TreeNode root = new TreeNode(postorder[this.index]);
  int tmp = getIndex(inorder , begin , end , postorder[this.index]);
  if(tmp == -1){
   return null ;
  }
  this.index -- ;
  root.right = buildTreeChild(inorder,tmp+1 , end, postorder);
  root.left = buildTreeChild(inorder , begin , tmp - 1 , postorder);
  return root;
 }

 private int getIndex(int[] inorder ,int begin , int end, int key){
  for(int i = begin ; i<= end ; i++){
   if(inorder[i] == key){
    return i ;
   }
  }
  return -1 ;
 }
}